<?php
/**
 * PHP Class
 *
 * LICENSE
 *
 * Processing: Cache
 *
 * @category   	Gnn Cms
 * @package    	Gnn Cache
 * @copyright  	Copyright vinanewstar.vn@gmail.com
 * @author		GiangNam (vinanewstar.vn@gmail.com)
 * @license    	GNU General Public License Version 2 or later (the "GPL")
 * @version     v1.0 Jun 4, 2013 || 11:01:03 AM
 */
class Zendvn_Cache{
	/**
	 * Return the Other Cacher
	 * @param int $timeout
	 * @return Ambigous <Zend_Cache_Core, Zend_Cache_Frontend, mixed>
	 */
	public static function getOtherCacher($timeout = GLOBAL_CACHING_OTHER, $frontend = "Core"){
		$backend  		 = 'File';
		$frontendOptions = array(
								'cat_id_prefix'=>'gcmscaching_other_',
								'lifetime'=>$timeout,
								'automatic_serialization' => true 
								);
		$backendOptions = array('cache_dir'=>CACHE_PATH_LANGUAGE);
		return   Zend_Cache::factory($frontend, $backend, $frontendOptions , $backendOptions);
	}
	/**
	 * Return the Language Cacher
	 * @param int $timeout
	 * @return Ambigous <Zend_Cache_Core, Zend_Cache_Frontend, mixed>
	 */
	public static function getLanguageCacher($timeout = GLOBAL_CACHING_LANGUAGE){
		$frontend 		 = 'Core';
		$backend  		 = 'File';
		$frontendOptions = array(
								'cat_id_prefix'=>'gcmscaching_lang_',
								'lifetime'=>$timeout,
								'automatic_serialization' => true 
								);
		$backendOptions = array('cache_dir'=>CACHE_PATH_LANGUAGE);
		return   Zend_Cache::factory($frontend, $backend, $frontendOptions , $backendOptions);
	}
	/**
	 * Return the Module Cacher
	 * @param int $timeout
	 * @return Ambigous <Zend_Cache_Core, Zend_Cache_Frontend, mixed>
	 */
	public static function getModuleCacher($timeout = GLOBAL_CACHING_MODULE){
		$frontend 		 = 'Core';
		$backend 		 = 'File';
		$frontendOptions = array(
								'cat_id_prefix'=>'gcmscaching_module_',
								'lifetime'=>$timeout,
								'automatic_serialization' => true 
								);
		$backendOptions = array('cache_dir'=>CACHE_PATH_MODULE);
		return   Zend_Cache::factory($frontend, $backend,$frontendOptions , $backendOptions);
	}
	/**
	 * 
	 * @param Zend_Cache $cache | Zend Cache Object
	 * @param String $catche_id | Cache Id to load
	 * @param String $callBackClassName	
	 * @param String $callBackFunctionName
	 * @param Array $callBackFunctionParams
	 * 		|| in condition data not found, it will call $callBackClassName->$callBackFunctionName($callBackFunctionParams) 
	 * 		|| and save to caches
	 * @return result
	 */
	public static function getVariableFromCache($cache,$catche_id = null,$callBackClassObject = null,$callBackFunctionName = null,$callBackFunctionParams = null){
		$result = $cache->load($catche_id);
		if( $result == false){
			$result = $callBackClassObject->$callBackFunctionName($callBackFunctionParams);
			$cache->save($result,$catche_id);
		}
		return $result;
	}
}